package com.zhangyongyi.carhome.adapter.Forum.hot;

import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.zhangyongyi.carhome.R;
import com.zhangyongyi.carhome.entity.greendao.HotList;

import java.util.List;

/**
 * Created by dllo on 16/1/21.
 */
public class HotAdapter extends RecyclerView.Adapter<HotAdapter.MyViewHolder>{

    private List<HotList> hotLists;

    public void addData(List<HotList> datas) {
        hotLists = datas;
        notifyDataSetChanged();

    }


    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup viewGroup, int viewType) {
        LayoutInflater inflater = LayoutInflater.from(viewGroup.getContext());
        View view = inflater.inflate(R.layout.item_hot, null);

        return new MyViewHolder(view);
    }

    @Override
    public void onBindViewHolder(MyViewHolder holder, int position) {
        if (hotLists != null && hotLists.size() > 0) {
            HotList list = hotLists.get(position);
            holder.title.setText(list.getTitle());
            holder.replycount.setText(String.valueOf(list.getReplycounts()));
            holder.bbsname.setText(list.getBbsname());
        }
    }

    @Override
    public int getItemCount() {
        return hotLists != null && hotLists.size() > 0 ? hotLists.size() : 0;
    }

    class MyViewHolder extends RecyclerView.ViewHolder {
        private TextView bbsname, replycount, title;

        public MyViewHolder(View itemView) {
            super(itemView);
            bbsname = (TextView) itemView.findViewById(R.id.tv_bbsname_hot_item);
            replycount = (TextView) itemView.findViewById(R.id.tv_replycount_hot_item);
            title = (TextView) itemView.findViewById(R.id.tv_title_hot_item);
        }
    }

}
